//
//  ChangeNicknameVM.swift
//  LeTu
//
//  Created by gy on 2023/12/7.
//

import Foundation

class ChangeNicknameVM {
    
    private(set) var viewType = ChangeUserInfoViewType.inviteCode

    init(viewType: ChangeUserInfoViewType) {
        self.viewType = viewType
    }
    
    // MARK: - 修改昵称
    func modifyNickname(_ nickname: String, completeHandle: @escaping NetworkRequestHandle) {
        
        apiProvider.request(api: .modefyNickname(params: ["nickname": nickname])) { json, jsonArr, code in
                        
            MYLog("修改昵称：\(json)")
            var dialog = DialogMessage()
            guard code == 200, let respone = Mapper<ResponseModel>().map(JSON: json) else { return completeHandle(dialog) }
            dialog.code = respone.code
            dialog.message = respone.msg
            completeHandle(dialog)
            
        } failureHandler: { error in
            completeHandle(DialogMessage())
        }
        
    }
    
    // MARK: - 兑换码
    func redemptionCode(_ code: String, completeHandle: @escaping NetworkRequestHandle) {
        
        apiProvider.request(api: .redemptionCode(redemptionCode: code)) { json, jsonArr, code in
                        
            MYLog("兑换码：\(json)")
            var dialog = DialogMessage()
            guard code == 200, let respone = Mapper<ResponseModel>().map(JSON: json) else { return completeHandle(dialog) }
            dialog.code = respone.code
            dialog.message = respone.msg
            completeHandle(dialog)
            
        } failureHandler: { error in
            completeHandle(DialogMessage())
        }
        
    }
    
}

